package com.itheima.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class SockdetDemoGuangBo02 {
    public static void main(String[] args) throws IOException {
        //创建接受对象
        DatagramSocket da=new DatagramSocket(8080);
        byte[]bytes=new byte[1024];
        //接收数据
        DatagramPacket dp=new DatagramPacket(bytes,bytes.length);
        //把接收的数据放入箱子
        da.receive(dp);
        byte[] data = dp.getData();
        int length = dp.getLength();
        System.out.println(new String(data,0,length));
        da.close();
    }
}
